<template>
  <div class="mainua">
    <div class="main_spac1" style="padding-bottom: 5px">
      <div class="main_white padding10">
        <div class="main_crumbs boxdq">
          <div class="main_crumbs_l">
            <a href="javascript:;" @click="$router.back(-1)">
              <i class="el-icon-arrow-down"></i>返回
            </a>
            <em>|</em>
            <span>{{ title }}</span>
          </div>
        </div>
        <div class="main_tile boxdq marginTop10">
          <div class="main_tile_l"><em></em>基本信息</div>
        </div>
        <div class="content">
          <el-row>
            <el-col :span="3" class="label">客户类型：</el-col>
            <el-col :span="12" class="value">{{
              data.company_type ? data.company_type.name : null
            }}</el-col>
          </el-row>
          <el-row v-show="documentType != 3 && documentType != 4">
            <el-col :span="3" class="label">产品：</el-col>
            <el-col :span="12" class="value">{{
              data.product ? data.product.name : null
            }}</el-col>
          </el-row>
          <el-row v-show="documentType != 3 && documentType != 4">
            <el-col :span="3" class="label">所属菜单：</el-col>
            <el-col :span="12" class="value"
              >{{ data.menu_first ? data.menu_first.name : null }} /
              {{ data.menu_sec ? data.menu_sec.name : null }}</el-col
            >
          </el-row>
          <el-row>
            <el-col :span="3" class="label">标题：</el-col>
            <el-col :span="12" class="value">{{ data.title }}</el-col>
          </el-row>
          <el-row v-if="documentType != 4">
            <el-col :span="3" class="label">作者：</el-col>
            <el-col :span="12" class="value">{{ data.author }}</el-col>
          </el-row>
          <el-row v-if="documentType != 4">
            <el-col :span="3" class="label">查看次数：</el-col>
            <el-col :span="12" class="value">{{ data.view_num }}</el-col>
          </el-row>
          <el-row v-if="documentType != 4">
            <el-col :span="3" class="label">发布状态：</el-col>
            <el-col :span="12" class="value">{{
              data.status == 1 ? "已发布" : "未发布"
            }}</el-col>
          </el-row>
          <el-row>
            <el-col :span="3" class="label">创建时间：</el-col>
            <el-col :span="12" class="value">{{
              parseTime(data.created_at)
            }}</el-col>
          </el-row>
        </div>
        <div class="main_tile boxdq">
          <div class="main_tile_l"><em></em>内容</div>
        </div>
        <div class="maincla_ed">
          <Editor
            api-key="vl7byj8kh7hyvvi6o7137s7khcpfsp762987dlnbcd93u37a"
            v-model="data.content"
            :init="init"
          ></Editor>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { parseTime } from "@/utils/index";
import Editor from "@tinymce/tinymce-vue";
import init from "@/views/document/detail_init";
import {
  companyManualBaseData,
  addCompanyManual,
  companyManualDetail,
  editCompanyManual,
} from "@/api/document/document";
import { apiUrl, objKeySort, Md5 } from "@/utils/public";
import { recursion, category } from "@/utils/index";

export default {
  components: {
    Editor,
  },
  data() {
    return {
      id: null,
      documentType: 1, //类型：1：用户手册，2：常见问题 3.更新记录 4.站内通知
      title: "查看", //头部标题
      menuList: [], //菜单列表
      init, // 富文本
      info: {}, // 信息
      data: {},
      parseTime,
    };
  },
  mounted() {
    this.id = this.$route.query.id;
    console.log(this.$route.meta.navigation)
    this.getDetail(this.id);
    let tit = "查看";
    this.title = tit;
  },
  methods: {
    getDetail(id) {
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, { id })) +
              apiUrl().appsecret
          ),
        },
        apiUrl().name,
        { id }
      );
      companyManualDetail(data).then((res) => {
        if (res.errcode == 0) {
          this.data = res.data.info;
          this.menuList = res.data.company_menu_list;
          // for(let i in this.menuList){
          //    if(this.data.type == this.menuList[i].id){
          //       this.data.typeName = this.menuList[i].name;
          //    }
          // }

          // this.form.title = data.title;
          // this.form.author = data.author;
          // this.form.content = data.content;
          // this.form.status = data.status;
          // this.menuIds = [data.type];
          // data.product_type > 0 ? this.menuIds.push(data.product_type) : null;
          // data.first_menu_id > 0 ? this.menuIds.push(data.first_menu_id) : null;
          // data.sec_menu_id > 0 ? this.menuIds.push(data.sec_menu_id) : null;
          // console.log(this.menuIds);
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
  },
  created() {},
};
</script>
<style lang="scss" scoped>
.content {
  padding: 10px 20px;
  .el-row {
    margin-bottom: 10px;
    .label {
      color: gray;
      text-align: right;
    }
  }
}
</style>
